VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Derived"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'***************************************************************
' (c) Copyright 2000 Matthew J. Curland
'
' This file is from the CD-ROM accompanying the book:
' Advanced Visual Basic 6: Power Techniques for Everyday Programs
'   Author: Matthew Curland
'   Published by: Addison-Wesley, July 2000
'   ISBN: 0-201-70712-8
'   http://www.PowerVB.com
'***************************************************************
Option Explicit

Implements IDelayCreation

'Type for stack alloc
Private Type InitData
    AggData(0) As AggregateData
    IIDs(0) As VBGUID
End Type

Private m_Hook As UnknownHook
Private m_BaseOverride As BaseOverride
Private m_Base As Base

Private Sub Class_Initialize()
Dim InitData As InitData
Dim LastIID As LastIID
    
    'Get the IID for the base class.
    InitLastIID LastIID
    On Error Resume Next
    Set m_Base = LastIID.QIThis
    On Error GoTo 0
    Set m_Base = New Base
    
    m_Base.SetOuter Me
    InitPushParamThunk m_BaseOverride.OverrideMeThunk, ObjPtr(Me), AddressOf Derived_OverrideMe
    With InitData
        With .AggData(0)
            .Flags = adUseIIDs Or adNoDelegator Or _
              adDelayDontCacheResolved Or adFullyResolved
            .FirstIID = 0
            Set .pObject = Me
        End With
        .IIDs(0) = LastIID.IID
        VBoost.AggregateUnknown Me, .AggData, .IIDs, m_Hook
    End With
End Sub

Private Function IDelayCreation_Create(IID As VBoostTypes.VBGUID) As stdole.IUnknown
    'We only specified 1 IID, so we don't
    'have to check if we got the right one.
    'If there is more than one override, then
    'store the IID's at module level.
    With m_BaseOverride
        If .BD.cRefs Then
            VBoost.AssignAddRef IDelayCreation_Create, VarPtr(.BD)
        Else
            Set IDelayCreation_Create = VBoost.CreateDelegator(Me, m_Base, , VarPtr(.BD))
            modDerived.HookVTable .BD.pVTable
        End If
    End With
End Function

Friend Function Base_OverrideMe() As String
    Base_OverrideMe = m_Base.OverrideMe & _
      " overridden by Derived"
End Function
